const express = require('express')
const search = express.Router()

// 引入数据库
const db = require('../utils/db')

/* 获取关键字对应的商家 */
search.get('/getpwdshop', (req, res) => {
   const { pwd } = req.query
   const sql = `SELECT * FROM shoplists WHERE shopname LIKE '%${pwd}%' OR content LIKE '%${pwd}%' OR fee LIKE '%${pwd}%' OR kwd LIKE '%${pwd}%'`
   db.query(sql, (err, results) => {
      if (results.length >= 1) {
         res.json({ code: 1, msg: 'ok', shops: results })
      } else res.json({ code: 1, msg: 'none' })
   })
})

module.exports = search